home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Development Platforms / Apple II / Essentials / GSBug / GSBug.Tutorial < prev    next >
Encoding:
Text File  |  1992-07-01  |  29.5 KB  |  622 lines  |  [TEXT/pdos]

  1.  
  2.  
  3.  
  4.  
  5.                              GSBug is Your Friend
  6.                            (a quick intro to GSBug)
  7.                                v1.3    1-Jul-92
  8.                          by Tim Swihart and Dave Lyons
  9.  
  10.  
  11.  
  12. So, you just got GSBug installed for the first time and don't have a clue how
  13. to use it.  Sure, you could call Resource Central (1-913-469-6502) and order
  14. the complete package, but you're not sure if GSBug will really help you find
  15. those nasty bugs in the Apple IIGS software you're developing.  Well, from the
  16. next paragraph until the end of this file, we'll present a quick introduction
  17. to some of the reasons why GSBug is a "MUST HAVE" tool for all IIGS developers.
  18. It doesn't matter what language you program in, or which environment you use,
  19. GSBug is the key to tracking down and exterminating those nasty bugs that make
  20. your software look shabby.
  21.  
  22.  
  23. Installation
  24.  
  25. Before we can really get into it, you need to install GSBug and the
  26. GSBug.Templates file and reboot your IIGS.  If you only have one computer,
  27. then print this file and continue reading from the printout.  GSBug is an INIT
  28. with the file name "Debug.Init" - install it by copying this file into your
  29. boot disk's System/System.Setup folder.  Copy the "GSBug.Templates" file into
  30. the same folder.
  31.  
  32. Over the course of time, the name used for the GSBug init file has changed
  33. slightly.  To be certain you don't accidentally install two (or more) copies
  34. of GSBug, carefully examine the contents of the System/System.Setup folder on
  35. your boot disk.  If you see more than one file with a name similar to
  36. "Debug.Init" (such as "gsbug.init" or "GSBug1.5B11init") then take out all but
  37. the most recent one.  Having more than one copy of GSBug causes problems (such
  38. as crashes during booting).
  39.  
  40.  
  41. Care & Feeding of GSBug
  42.  
  43. Now that everything is installed, reboot your computer.  No need to launch any
  44. particular application just yet, we have to explain the various parts of
  45. GSBug's screen and we want to cover a few basic GSBug commands before we go bug
  46. hunting.  We'll assume you're running the Finder right now, but it really
  47. doesn't matter a whole lot what application is running, as long as it is a
  48. 16-bit application (that is, a true IIGS application).
  49.  
  50. You can pop into GSBug at any time (assuming interrupts aren't disabled) by
  51. pressing OPEN APPLE-OPTION-CONTROL-ESC  (if you're having troubles remembering
  52. all of those keys at once, just think of it as the same keys that you use to
  53. get to the built-in control panel plus the OPTION key).  You'll be presented
  54. with a rather busy-looking 80-column text screen.  (there's a screen dump
  55. right below this paragraph - we told you it was busy-looking screen)
  56.  
  57.  
  58. ------ beginning of screen dump ------
  59.  
  60. Key BRKs  DebugD  K/PC   B   D    S    A    X    Y    M   Q   L  P  nvmxdizc e i
  61. 00     d   9500  FD/688D FD 2500 1FE0 0000 4D95 0044  0C  BE  1  03 00000011 0 0
  62.  
  63. 1FF2:60  00/0000:  BE '>'  00/0000-00-00
  64. 1FF1:43  00/0000:  BE '>'  00/0000-00-00
  65. 1FF0:FE  00/0000:  BE '>'  00/0000-00-00
  66. 1FEF:01  00/0000:  BE '>'  00/0000-00-00
  67. 1FEE:37  00/0000:  BE '>'  00/0000-00-00
  68. 1FED:0C  00/0000:  BE '>'  00/0000-00-00
  69. 1FEC:00  00/0000:  BE '>'  00/0000-00-00
  70. 1FEB:4D  00/0000:  BE '>'  00/0000-00-00
  71. 1FEA:7A  00/0000:  BE '>'  00/0000-00-00
  72. 1FE9:C0  00/0000:  BE '>'
  73. 1FE8:00  00/0000:  BE '>'  E1/0000.000F-T
  74. 1FE7:2C  00/0000:  BE '>'  01/FC00.FFFF-T
  75. 1FE6:00  00/0000:  BE '>'  00/0000.0000-?
  76. 1FE5:E0  00/0000:  BE '>'  00/0000.0000-?
  77. 1FE4:6A  00/0000:  BE '>'  00/0000.0000-?
  78. 1FE3:B4  00/0000:  BE '>'  00/0000.0000-?
  79. 1FE2:62  00/0000:  BE '>'  00/0000.0000-?
  80. 1FE1:DA  00/0000:  BE '>'  00/0000.0000-?
  81. 1FE0:FD  00/0000:  BE '>'  00/0000.0000-?
  82.  
  83. :GSBug v1.6 w/Glue & P8 Support (C) 1986-92 Apple Computer, Inc.
  84.  
  85. ------    end of screen dump    ------
  86.  
  87.  
  88. Top Two Lines
  89.  
  90. The first two lines of the screen show the contents of various registers.  The
  91. top line of the screen starts off with "Key BRKs  DebugD" - those are headings
  92. for the items in the second line of the screen.  The meanings of those
  93. headings (and the items under them) are:
  94.  
  95. Heading     Meaning
  96. -------     -------------------------------------------
  97. Key         Modifiers used to separate debugger keys from application keys
  98.  
  99. BRKs        Below "BRKs" a combination of four characters show up, showing
  100.             how GSBug will handle various kinds of breaks:
  101.  
  102.               "b" means breakpoints are in (use "in" or "b+" to put them
  103.                   in, "out" or "b-" to take them out)
  104.  
  105.               "t" means tool breaks are in (use TBrkIn or "t+" to put them
  106.                   in, TBrkOut or "t-" to take them out; setting a tool break
  107.                   with SetTBrk automatically puts tool breaks in)
  108.  
  109.               "o" means OS breaks are in (use OSBrkIn or "o+" to put them
  110.                   in, OSBrkOut or "o-" to take them out; setting an OS break
  111.                   with SetOSBrk automatically puts OS breaks in)
  112.  
  113.               In the 4th position, you normally see a "d" for Debugger breaks;
  114.                   if you want to get dumped into the monitor instead, use
  115.                   "mbrk" ("dbrk" gets you back to Debugger breaks)
  116.  
  117. DebugD      Debugger's direct page (1K in size) - in bank $00
  118. K/PC        K=program bank, PC=program counter 
  119.  
  120. B           app's data bank
  121. D           current direct page in bank zero 
  122.  
  123. S           current stack pointer
  124. A           accumulator's value
  125.  
  126. X           X register's value
  127. Y           Y register's value
  128.  
  129. M           machine state register's value
  130. Q           quagmire register's value
  131.  
  132. L           Language card bank
  133. P           processor-status register's value
  134.  
  135. nvmxdizc    bits that make up "P" (n=negative, c=carry, etc)
  136. e           emulation mode flag
  137. d           disassembly mode flag (0=recognize SEP & REP during "L"isting)
  138.  
  139.  
  140. If you want more information on a specific register's meaning then look it up
  141. in the IIGS Hardware reference manual, the GSBug manual, or any good book that
  142. covers the IIGS's internal hardware.  Any of these register's values can be
  143. changed - we'll show how to do that in a few paragraphs or so.
  144.  
  145.  
  146. The Left-Hand Side
  147.  
  148. The next major area of the screen is the 4-digit column of numbers running
  149. down the far left side.  There is a colon on each line after the fourth
  150. digit, and then there is a column (two digits wide) of numbers.  All of these
  151. numbers are in hex and this area is the stack.  The four digit column, the
  152. colons, and the two digit column are collectively known as the "stack
  153. subdisplay area" - remember that, there's a test at the end of this file.
  154. The column on the left of the colon is the address of the stack and the
  155. column on the right (the two digit column) are the values on the stack.
  156. The bottom-most four digit stack address is the "top" of the stack (that is,
  157. if your app pushes anything on the stack, that's the address it would wind
  158. up at).  As you step through your application (we'll show how in a minute,
  159. patience) the stack will scroll upwards as things are pushed onto it and
  160. downwards as things are pulled off of it.
  161.  
  162.  
  163. The Not-So-Left-Hand Side
  164.  
  165. The next major area should be a column of "00/0000:  BE '>'" known as the
  166. "RAM subdisplay area".  This area is used to display any 19 memory locations
  167. that you want to keep an eye on.  The value at each of those locations is
  168. shown in hex (that's what the "BE" means - location 00/0000 contains hex "BE"
  169. when we wrote this) and in ASCII (the ASCII version is between the single
  170. quote marks, the "'>'").  It is possible to have this subdisplay show a
  171. two-byte or a three-byte value instead of the one-byte value.  You lose the
  172. ASCII display if you opt for the 2 or 3 byte values.
  173.  
  174. After we finish explaining the rest of the screen, we'll come back and
  175. describe how to change these 19 "windows on memory" to look at what you want
  176. to monitor.
  177.  
  178.  
  179. The Center Part
  180.  
  181. The next major area of the screen is the 9 lines of "00/0000-00-00", better
  182. known as the "Breakpoint subdisplay" (they're on the top half of the screen).
  183. GSBug lets you set up to 17 breakpoints in your program (not counting BRK
  184. instructions you imbed in your program yourself).  Curious about how you set
  185. 17 break points when there are only 9 lines in this section?  Did we mention
  186. that Resource Central stocks the manual? <grin>  Seriously, you can "extend"
  187. the breakpoint subdisplay by shrinking the section under it (which we haven't
  188. described yet).  For the purposes of this quick intro, We're not going to show
  189. how to do this (you need some kind of reason to get the manual).  We'll just
  190. describe this area and later show how to set up to 9 break points.
  191.  
  192. The "00/0000" part of the breakpoint subdisplay is obviously an address - in
  193. fact, it's the address you want to break on.  The next part "-00-" is the
  194. trigger value.  GSBug is smart enough to count how many times an address has
  195. been executed and break on a certain number (for example, put a "03" here and
  196. GSBug will break the third time that address is executed).  The last part of
  197. this area is the running count - this is how GSBug lets you know how many times
  198. that area has been executed (rather than leave you wondering, it tells you and
  199. you can be ready for the break).  You set the address and trigger portions and
  200. GSBug sets the count portion.
  201.  
  202.  
  203. The Bottom Part of the Center Part
  204.  
  205. The bottom half of the center of the screen is known as the "Memory
  206. Protection Subdisplay" and starts off with "E1/0000.000F-T".  This area can
  207. be expanded (or shrunk) by trading lines of this area for lines of the one
  208. above it (the "Breakpoint subdisplay").  If you want to know how to do this,
  209. read the manual from Resource Central, it's big (roughly 140 pages) and we're
  210. not retyping all of it here!  <grin>
  211.  
  212. The "E1/0000.000F" is the address range starting at E1/0000 and ending at
  213. E1/000F.  The "T" at the end means that this range of memory is protected from
  214. code tracing.  If you're tracing through your code and it jumps (JSR's, JSL's,
  215. whatever) into this range of memory, then the code in this range will NOT be
  216. traced - it will be executed at full speed instead.
  217.  
  218. There are two other options for code protection ("W" and "H").  They are
  219. beyond the scope of this quick tutorial (we're only trying to cover the
  220. basics here).
  221.  
  222.  
  223. Where You Type Commands
  224.  
  225. The bottom line on the screen is the command line subdisplay (catchy name,
  226. eh?).  When you first enter GSBug, this line will contain the copyright
  227. message and version number for GSBug (unless you've used the DebugStr or
  228. SetMileStone "tool" calls to change this string).  As soon as you press a
  229. key, the copyright message vanishes and your keypress shows up next to the
  230. blinking cursor.  This is where you'll type various commands to make GSBug
  231. help you get the kinks out of your software.
  232.  
  233.  
  234. What's the Big Blank Spot For?
  235.  
  236. The big blank area towards the far right of the screen is officially known as
  237. the "disassembly subdisplay" (it's one of the big reasons you're using GSBug -
  238. even if you don't know it yet).  As you single-step through your software,
  239. trace through it, or just list areas of memory this area will show you the
  240. disassembled version of your program.  One of the really slick things about
  241. this area is that it's smart enough to know about the names of GS/OS calls and
  242. Toolbox calls - so you see things like "_CheckUpdate" instead of "JSL E10000".
  243. That makes if VERY easy to line up pieces of your source with the disassembly
  244. if you're working in a high-level language.  It also makes it a LOT easier to
  245. see what you're doing!
  246.  
  247. GSBug also knows about the alternate Toolbox entry point (E10004) and will
  248. display those as tool calls also.  The leading underscore ("_") lets you know
  249. that GSBug is substituting the tool's name for you.  If the tool call is being
  250. made through "glue", then the underscore is preceded by an asterisk ("*").
  251.  
  252. If you've ever used the built in "monitor" (we're not talking about your RGB
  253. monitor, we're talking about the disassembler that's been built into Apple IIs
  254. for a LONGGGGGGG time now), then you'll be able to quickly figure out that
  255. the left-most part of the disassembly subdisplay is the address, the inside
  256. columns are the hex bytes making up the code about to be disassembled, and the
  257. right-most part is the disassembled version of your software.
  258.  
  259.  
  260. Your First GSBug Command
  261.  
  262. OK, you now know what all of the various areas of this rather busy-looking
  263. screen are for, so let's get down to business!  The first thing to do is press
  264. the "L" key (upper and lower case work the same these days) and then press
  265. RETURN.  This will fill the disassembly subdisplay with 19 lines of
  266. disassembled code (which 19 lines were disassembled really doesn't matter).
  267. Study it until you can tell at a glance which parts are the address, which
  268. parts are the hex bytes, and which parts are the disassembled code.
  269.  
  270. Type "L" and press RETURN again - you get the next 19 lines of memory (see,
  271. we told you it was a lot like the built-in monitor).
  272.  
  273. Now, let's do something a tad more useful.  Press the "S" key and RETURN
  274. (you just told GSBug to start single-stepping through your application).  Be
  275. careful what keys you press while in the single step mode - lots of
  276. weird-looking things can happen (they're all normal, but if you don't expect
  277. them you can get confused).  For now, ONLY press the keys this tutorial tells
  278. you to.  If you can't wait and just HAVE to bang on all of the various keys,
  279. then go ahead - reboot once you've totally confused yourself, pop back into
  280. GSBug and catch up with the rest of the folks reading this.
  281.  
  282. To tell GSBug to execute the highlighted instruction, press the SPACE BAR one
  283. time.  Heck, press it several times so that you get a bunch of lines of
  284. disassembled code on the screen.  Notice that the code scrolls up and the
  285. "highlighted" area stays in the same place?  Notice it's kind of close to the
  286. bottom of the screen?  Later we'll tell you how to move it up higher.
  287.  
  288. Press the ESC key.  That takes you out of single-step and returns you to the
  289. command line.  Press "S" and RETURN again to restart single stepping.  Notice
  290. that the lines ABOVE the highlighted area have been erased?  Remember that -
  291. if you halt single-stepping and need some piece of info above the highlighted
  292. area, then write it down because it'll be wiped out when you restart
  293. single-stepping (or when you do any of a bunch of different things).  If you
  294. have your printer connected to slot 1, then you can print GSBug's screen using
  295. the "P" command (press "P" and RETURN - be sure you're NOT single-stepping
  296. when you do this, "P" only prints from the command line).
  297.  
  298.  
  299. Lock a Tractor Beam onto Them...
  300.  
  301. Want an easy way to have the computer step through source for you without
  302. having to bang again and again on the SPACE BAR?  Start single-stepping
  303. ("S" and RETURN), then press RETURN again.  VRRRROOOOMMMMMM!  Can't read all
  304. the stuff flying by?  No sweat, press SPACE BAR and you'll be back to
  305. single-stepping.  Pressing the RETURN key a second time kicked GSBug into
  306. "Trace" mode.
  307.  
  308. Trace actually has two speeds, the default is fast (we like to test
  309. developers' speed reading skills).  To kick TRACE into low gear, press the
  310. left arrow key.  If you're in single-step mode, then you won't see the speed
  311. change (after all, it affects TRACE, not SINGLE-STEP), but fear not brave
  312. developer, the speed change has been made.  Press RETURN again (to be sure
  313. you're in TRACE mode) and press the left arrow key (if you didn't a few lines
  314. ago) to kick TRACE into low gear.  Want to get back into high gear?  Press the
  315. right arrow key (sneaky, eh?).
  316.  
  317.  
  318. RED ALERT!
  319.  
  320. Do _NOT_ press the down arrow key while TRACING or single-stepping (unless
  321. you know what you're doing).  The down arrow key tells GSBug to SKIP the
  322. highlighted instruction!  This is a great way to step over BRK instructions,
  323. but it's not a real smart thing to do at random while TRACING through an
  324. application (randomly skipping an instruction generally results in a crash).
  325.  
  326.  
  327. Move That Line Up
  328.  
  329. If you want to raise the highlighted line within the disassembly subdisplay,
  330. then press ESC (to get back to the command line) and type "SET" (don't type
  331. the quotes, OK?) and press RETURN.  The up and down arrows now control the
  332. vertical position of the highlighted bar within the disassembly subdisplay.
  333. Position the bar where you want it and press ESC.  That position will be
  334. remembered until the next time you move it or until you reboot (then it goes
  335. back to the default position).  The manual for GSBug tells you how to save
  336. this new position to a configuration file (it also tells you that pressing the
  337. left and right arrow will move the stack subdisplay up and down, and that
  338. pressing a number less than eight will change the slot used to print the
  339. screen).
  340.  
  341.  
  342. Reaching the Breaking Point
  343.  
  344. Alright, time for some fancy stuff!  The next couple of sections will assume
  345. you were running the IIGS Finder when you popped into GSBug (other apps will
  346. work just fine, but why be difficult?).  GSBug will let you break on any tool
  347. call (or calls) that you specify, so let's set a few tool breaks and learn how
  348. to use this feature.
  349.  
  350. From GSBug's command line (press ESC if you're still stepping or tracing),
  351. type "settbrk _sysbeep" and press RETURN.  If GSBug beeps at you instead of
  352. accepting this line, then you didn't type it right (there are two t's in
  353. "settbrk" and don't type the quotes).  Type "settbrk #090E" and press RETURN.
  354. You just added two tool calls to GSBug's list of tools to break on.  The first
  355. one was added by naming the tool to break on ("_sysbeep") and the second one
  356. was added by specifying the tool's number ("#090E").  This lets you set tool
  357. breaks regardless of whether you know the tool's name or number.
  358.  
  359. Type "showbrks" (or "sh") and press RETURN to see the complete list of tool
  360. breaks that GSBug has been told about.  Notice that the left hand side of
  361. the screen now implies that you can set breaks on GS/OS calls?  That's
  362. because you can!
  363.  
  364. Now, when either a call to SysBeep or a call to NewWindow (tool $090E is
  365. NewWindow) is made, we'll be dropped back into GSBug.
  366.  
  367.  
  368. Oh Yeah?  Prove It!
  369.  
  370. Make sure you're at GSBug's command line (press ESC if you aren't).  Type "R"
  371. and RETURN.  This resumes full execution of your application.  To test the
  372. tool breaks we just set, we need to force the Finder (or whatever app you
  373. stubborn folks decided to use instead of the Finder) to make a call to
  374. NewWindow and/or to SysBeep.  Double click on a disk icon, get info on a file,
  375. open a folder, open a desk accessory, etc to get the Finder to open a new
  376. window.  Notice that you land in GSBug?
  377.  
  378. Press "S" and RETURN to enter single-stepping.  Notice that the highlighted
  379. instruction is "NewWindow".  Ah, the tool break works.  Now, press SPACE BAR
  380. to execute the NewWindow call, press ESC to stop single-stepping, and type "R"
  381. and RETURN to resume running the Finder.  (if we didn't bother to single step
  382. across the NewWindow call, we would just fall right back into the debugger
  383. since we have a break point set on that call).
  384.  
  385.  
  386. Take it Out, Wise Guy!
  387.  
  388. Tired of falling into GSBug every time a new window is opened?  There are
  389. several ways to remove tool breaks.  The easiest way is to type "tbrkout"
  390. or "t-" to stop breaking on the listed tool calls without trashing the list.
  391. Typing "tbrkin" (or "t+") makes GSBug start breaking on them again.
  392.  
  393. To clear the list of tool breaks, either type "clrtbrk _sysbeep" (to remove
  394. the sysbeep break we put in earlier) and repeat that for "_newwindow" or wipe
  395. the all out with "clralltbrks".  "ctb" is shorthand for ClrTBrk, and if you
  396. don't specify which tool call to stop breaking on, it clears them all.
  397.  
  398.  
  399. Cheap Trick #1
  400.  
  401. Being able to break into the debugger based on a tool call is VERY handy!  But
  402. what if you want to see the stack being set up BEFORE your code gets all the
  403. way down to the tool call itself?  After all, if you're not putting enough
  404. parameters on the stack (or too many), then breaking on the tool call itself
  405. is too late to watch the stack being built.  There's an easy solution for
  406. this - stick a SysBeep call in your source ABOVE the tool call you really
  407. want to break on and set a tool break on SysBeep.  This will let you
  408. single-step through the stack setup for the call you're really interested in.
  409. OK, so it's a cheap trick, but it's darned effective.
  410.  
  411. This trick was invented in the dark ages before DebugStr was part of GSBug
  412. (DebugStr is explained near the very end of this document and is a little
  413. trickier to use than Cheap Trick #1).
  414.  
  415.  
  416. I Don't Like My Registers
  417.  
  418. Remember earlier when we mentioned that you can change the values of the
  419. various registers from within GSBug?  This lets you change values that are
  420. about to be pushed on the stack and do all kinds of neat things.  You're
  421. sharp, so we won't bore you with all the things this lets you do, we'll
  422. just cut right to the description of HOW to do it.
  423.  
  424. To change the accumulator's value, type "a=value" on the command line.
  425. Replace "value" with the hex value you want  to stuff into the accumulator.
  426. Type "x=value" to set the x register, "y=value" to set the y register, etc.
  427. You can't type "a=x" to set the accumulator to the value in the x register,
  428. but since you can see the x register's value, this isn't that big of a loss.
  429.  
  430.  
  431. Cheap Trick #2
  432.  
  433. If you accidently SKIP an instruction that you didn't mean to (and you haven't
  434. executed any more since then), you can "unskip" it by exiting single-step
  435. mode, then type "pc=value" where "value" is the address (all three bytes just
  436. to be safe) that the skipped instruction is at.  Press RETURN and then resume
  437. single-stepping (notice that you're back at the skipped instruction now).
  438.  
  439. This tricks works because the "pc" register is the program counter (the thing
  440. that determines what address will have its instruction executed next).
  441.  
  442.  
  443. Cheap Trick #3
  444.  
  445. Fudging the program counter (pc=value) will let you push extra info on the
  446. stack in cases where you didn't push enough for a call.  Be careful with
  447. this - you may need to set the accumulator before re-executing an
  448. already-executed PHA and you could totally trash the stack if you're not
  449. paying attention.  One place this is handy is to compensate for passing a
  450. WORD instead of a LONG (easy to do with C when you're dealing with resource
  451. ID's).  If you don't understand this trick, don't use it!
  452.  
  453. A minor modification on this stunt is (obviously) to pull extra bytes OFF of
  454. the stack in cases where you left something on there that shouldn't have been
  455. left on.  Once you spot problems like too much or too little data on the
  456. stack, FIX YOUR SOURCE CODE AND RECOMPILE IT!!!!  You don't really want to
  457. have to find this bug a second time do you?
  458.  
  459.  
  460. Cheap Trick #4
  461.  
  462. GSBug is a lot like the monitor in certain respects.  That means many of the
  463. commands you're used to from the monitor will work under GSBug.  Setting
  464. values in memory under GSBug is done just like it is under the monitor
  465. (just  address : value1 value2 value3 value4 ...).   addressT and RETURN
  466. starts tracing at the memory location specified by "address".  addressS and
  467. RETURN starts single-stepping at the memory location specified by "address".
  468. addressL and RETURN lists 19 lines of disassemby starting at the memory
  469. location specific by "address".  You can even use the built-in mini assembler
  470. if you want (type "asm" and RETURN).
  471.  
  472.  
  473. Peering Into Memory
  474.  
  475. The 19 "windows on memory" can be used by typing "mem" and RETURN on the
  476. command line.  This puts the cursor on the far right of the first line in the
  477. RAM subdisplay area.  Type the address you want to watch and press RETURN.
  478. That will move you to the next line (so you can set the address for the second
  479. memory location).  If you want to see two bytes starting at that address,
  480. press "P".  To see three bytes, press "L".  "Z" toggles between direct-page
  481. and absolute addressing, ":" toggles between direct, 2-byte indirect, and
  482. 3-byte indirect addressing.  Press "?" for more info.
  483.  
  484. This provides a nice way to look at variables in memory, dereference
  485. pointers/handles, etc.  When the contents of any "peered into" location
  486. changes, the corresponding line on GSBug's screen will change also.
  487.  
  488.  
  489. Cheap Trick #5
  490.  
  491. (this one's actually not cheap, it's pretty danged useful!)  While
  492. single-stepping or tracing, you can see other "screens" by pressing various
  493. keys (this accounts for the weird effects we alluded to earlier).  Press "S" to
  494. see the SHR screen (your desktop application's desktop), "D" to see the double
  495. hi-res screen, "T" to see the text screen, "8" to see 80-column display, "4" to
  496. see 40-column display, "H" to see the Hi-Res screen, "L" for the Lo-Res screen,
  497. and ESC to exit single-stepping.  This lets you see your application's screen
  498. instead of GSBug's screen (makes it a LOT easier to debug your apps when you can
  499. see their screens).
  500.  
  501.  
  502. Don't Touch That Dial!
  503.  
  504. The material covered so far gives you a decent foundation to draw upon as you
  505. hunt bugs in your own software.  We've only lightly touched on what GSBug can
  506. really do (we're not typing all 140 or so pages of the manual into this
  507. "introduction" to GSBug).  GSBug offers a lot of power and capabilities that
  508. should be learned by all developers.
  509.  
  510. Before we wrap up this tutorial we want to cover the use of templates and
  511. describe some of the new features in GSBug v1.6 that aren't described in
  512. the printed manual.
  513.  
  514.  
  515. Templates By Jim
  516.  
  517. GSBug provides an easy way for you to view portions of memory through
  518. templates.  This allows you to "see" the data structures in memory just
  519. like they appear in the documentation (divided into various fields).  The
  520. GSBug.Templates file that you were supposed to have placed in the
  521. SYSTEM/SYSTEM.SETUP folder of your boot disk contains a complete set of
  522. templates for use with our interface files.  One of the Apple II Developer
  523. Technical Support Engineers put these templates together (and came up with
  524. a pretty neat way to build in a "help system" - so tell Jim "thanks" next
  525. time a template bails you out of a jam).
  526.  
  527. GSBug does NOT automatically load those templates unless you rename the
  528. file to "GSBug.AutoTemp" (see the "GSBug.Specs" file for more information).
  529. You have to tell GSBug to load them (and you can unload them later).  To load
  530. the templates, just type "LoadTemp"--if you don't put a pathname after LoadTemp,
  531. GSBug assumes you mean "*/System/System.Setup/GSBug.Templates".
  532.  
  533. To view a piece of memory with a template, simply determine the starting
  534. address of the template.  The starting address can be found in a number of
  535. ways - you can dereference a pointer that you just pushed on the stack, etc.
  536. Then, type an underscore, the type of structure you want used, a blank space,
  537. and the starting address (don't forget the bank).  (For example, if you know
  538. you have a grafport starting at location 06/15E4, type:  "_grafport 06/15E4"
  539. and press RETURN.
  540.  
  541. To use the built-in template help system that Jim came up with (thanks Jim!),
  542. just type: "_template" and press return.  This will give you a list of all
  543. the categories of help you can get more info on (such as ADB, FONTS, etc).
  544. The categories are grouped by toolbox manager.  To get details on a particular
  545. toolbox manager's tool calls, type "_toolmgrname" and press RETURN (replace
  546. "_toolmgrname" with the name of any tool manager - lead with an underscore or
  547. it won't work).  (for example, "_quickdraw" for details on QuickDraw II data
  548. structures)  For more details, read the separate documentation file on using
  549. the templates.
  550.  
  551. If you want to create your own custom templates, then read the GSBug manual
  552. (pages 86-88) or decipher the templates in the GSBug.Templates file.  To
  553. unload the templates (and free up the memory they're eating), type "killtemp"
  554. and press RETURN from GSBug's command line.
  555.  
  556.  
  557. Debugger Tool Calls
  558.  
  559. There are several fake tool calls that the debugger intercepts and acts on.
  560.  
  561. They are SetMileStone, DebugStr, DebugVersion, DebugStatus, DebugSetHook,
  562. and DebugGetInfo.  The two most important ones are SetMileStone and DebugStr.
  563.  
  564. SetMileStone simply changes the debugger's copyright message to be a string of
  565. your choice and lets your app keep running.  If you're having a problem
  566. figuring out where your code was last at before it jumped off into the weeds,
  567. then sprinkle SetMileStone calls into your source code (with different strings
  568. on each, of course).  Then, when your app chokes and dies, you'll be presented
  569. with the text from the last SetMileStone that was executed.
  570.  
  571. DebugStr works like SetMileStone (it changes the copyright string to something
  572. with info about your application) except it dumps you immediately into GSBug.
  573. This is a little more work than Cheap Trick #1, but you can line up your source
  574. easier (since you'll have the debug string's message to guide you).
  575.  
  576. DebugVersion and DebugStatus act just like normal version and status calls for
  577. regular tool sets - they simply allow you to verify whether GSBug is running
  578. and if so, what version of the debugger is running before you try to make any
  579. debugger tool calls.
  580.  
  581. The tool numbers and parameter lists for these calls are:
  582.  
  583. Name            Tool #  Parameter (returns)
  584. --------------  ------  ---------------------------------------------------
  585. DebugStatus     $06FF   (non-zero = true, ToolLocator error it not loaded)
  586. DebugStr        $09FF   pointer to Pascal-style string
  587. DebugVersion    $04FF   ($159F for v1.5B9, $16FF for v1.6)
  588. SetMileStone    $0AFF   pointer to Pascal-style string
  589. DebugSetHook    $0BFF   pointer to routine called by "n" cmd (see GSBug.Specs)
  590. DebugGetInfo    $0CFF   see GSBug.Specs
  591.  
  592.  
  593. Cheap (and short) Trick #6
  594.  
  595. If you get really fancy, you can build the strings for DebugStr and
  596. SetMileStone on the fly and imbed the values of key variables into them to
  597. further simplify locating bugs.
  598.  
  599.  
  600. Calling all Debuggers
  601.  
  602. Do _NOT_ leave calls to these debugger tools in your software when you ship it
  603. to customers!  Why?  Because making these calls on a system that doesn't have
  604. GSBug installed makes a real mess.
  605.  
  606.  
  607. Want More Info?
  608.  
  609. Contact Resource Central and order the full package.
  610.  
  611.     Resource Central, Inc.
  612.     P.O. Box 11250
  613.     Overland Park, KS 66207
  614.     
  615.     (913) 469-6502
  616.     Fax: (913) 469-6507
  617.     AppleLink: A2.CENTRAL
  618.     Internet: A2.CENTRAL@AppleLink.Apple.com
  619.     GEnie: RC.ELLEN
  620.  
  621. [end of GSBug.Tutorial]
  622.